#delimit;
pause on;
clear all;
set mem 50m;
pause;
set more off;
pause;
cd "C:\data\Veto points\JOP_December08\Replication";
pause;
use "veto0208_replication_v1.dta", clear;
log using reversals.smcl, replace;

/*Descriptive Information on Reversals*/

/*For individual reforms, here are the number of reversals*/
pause;
count if d.price <0;
count if d.forex <0;
count if d.small <0;
count if d.large <0;
count if d.entre <0;
count if d.comp <0;
count if d.bankr <0;
count if d.nonbank <0;
count if d.EBRD <0;
pause;

/*Reversals on Campos Measures of Reform*/
count if d.ilib <0;
count if d.elib <0;
count if d.priv <0;


/*Generate Measure of Cumulative Reversals Across All Measures of Reform*/

generate cum_reversals=0;
replace cum_reversals=1 if d.price <0 | d.forextrade <0  | d.smallpriv <0 | d.largepriv <0 | d.entreform <0 | d.comppolicy <0 | d.bankref <0 | d.nonbank <0;
replace cum_reversals=. if EBRD==.;
pause;

tab cum_reversals year, column nofreq;
pause;

tabstat cum_reversals, statistics(sum) by(year);
pause;
tabstat cum_reversals, statistics(sum) by( ctrynm);
pause;


/*Generate Total Reversals over the Entire Reform Period*/
by  country_, sort: egen total_reversals = sum(cum_reversals);
list  ctrynm total_reversals if year==2004;
pause;


/*Generate Magnitude of Reversals that takes into account the average size of the movement*/
foreach x in  price forextrade smallpriv largepriv entreform comppolicy bankref nonbank {;
generate reverse_`x'=1 if d.`x'<0;
replace reverse_`x'=0 if  d.`x'>=0 & d.`x' !=.;
};

generate reverse_magnitude=d.price*reverse_price+d.forextrade*reverse_forextrade+d.smallpriv*reverse_smallpriv+
d.largepriv*reverse_largepriv+d.entreform*reverse_entreform+d.comppolicy*reverse_comppolicy+
d.bankref*reverse_bankref+d.nonbank*reverse_nonbank;

by  country_, sort: egen mag_reversals2 = sum( reverse_magnitude);

generate l12checks=l12.checks_new;
generate l12postcom=l12.postcoms;
generate l12parcomp=l12.p_parcomp;


/*Descriptives*/
tabstat total_reversals, statistics(mean sd) by (year);
tabstat total_reversals, statistics(mean sd) by (year);
tabstat total_reversals, statistics(mean sd) by ( ctrynm);
pause;


/**************************************************************************************************************************************/

/*TABLE 2: Replication of Table 2: Veto Players and Reform Reversals 1992-2004*/

/*Model 1: Baseline*/
xi3: poisson total_reversals resource gnp89 distance2 gdp_en if year==2004, robust;
outreg2 using Table2, replace  bdec(3) tdec(3) e(all);

/*Model 2: Average Checks*/
xi3: poisson total_reversals checks_av   resource gnp89 distance2 gdp_en if year==2004, robust;
outreg2 using Table2,  bdec(3) tdec(3) e(all);

/*Model 3: Average Checks with Average Postcommunsists in Legislature*/
xi3: poisson total_reversals checks_av postcom_av  resource gnp89 distance2 gdp_en if year==2004, robust;
outreg2 using Table2,  bdec(3) tdec(3) e(all);

/*Model 4: Initital Values instead of Average Values*/
poisson total_reversals resource gnp89 distance2 gdp_en l12.checks_new  l12.postcoms if year==2004, robust;
outreg2 using Table2,  bdec(3) tdec(3) e(all);


/*Model 5: Magnitude of Reversals with Average Values*/
reg mag_reversals2 checks_av postcom_av  resource gnp89 distance2 gdp_en if year==2004, robust;
outreg2 using Table2,  bdec(3) tdec(3) e(all);


/*Model 6: Magnitude of Reversals with Initial Values*/
reg mag_reversals2 resource gnp89 distance2 gdp_en l12checks  l12postcom if year==2004, robust;
outreg2 using Table2,  bdec(3) tdec(3) e(all) excel;
pause;


/****************************************************************************************************************************/

/*Table A2: Summary Statistics; Cross Sectional Variables*/

/*Summary Statistics*/

xi3: poisson total_reversals checks_av l12.checks_new postcom_av  l12.postcoms  resource gnp89 distance2 gdp_en mag_reversals2 if year==2004, robust;
estat sum;
pause;

/*******************************************************************************************************************************/


/*Table A3: Bivariate Correlations; Cross Sectional Variables*/
pwcorr total_reversals checks_av postcom_av resource gnp89 distance2 gdp_en l12.checks_new l12.postcoms   mag_reversals2 if year==2004, star(5);


/*SAVE DATA BEFORE CLARIFY*/
save "veto0208_replication_v2.dta", replace;

/*****************************************************************************************************************************************/

/**************Construction of FIGURE 3A - ANALYSIS OF REVERSALS*******************************/




/*CLARIFY FOR POISSON PREDICTIONS BASED ON MODEL 3 ABOVE*/

estsimp poisson total_reversals checks_av  postcom_av resource gnp89 distance2 gdp_en if year==2004, robust;
setx mean;
setx checks_av p75;
simqi, prval(0 1 2 3 4 5) genpr(pr0_1 pr1_1 pr2_1 pr3_1 pr4_1 pr5_1);
setx checks_av p25;
simqi, prval(0 1 2 3 4 5) genpr(pr0 pr1 pr2 pr3 pr4 pr5);
pause;

collapse (mean) pr0_1 pr1_1 pr2_1 pr3_1 pr4_1 pr5_1 pr0 pr1 pr2 pr3 pr4 pr5;
sum pr*;
pause;

sum pr*;

label var pr0_1 "0";
label var pr1_1 "1";
label var pr2_1 "2";
label var pr3_1 "3";
label var pr4_1 "4";
label var pr5_1 "5";
pause;

label var pr0 "0";
label var pr1 "1";
label var pr2 "2";
label var pr3 "3";
label var pr4 "4";
label var pr5 "5";
pause;


graph bar (asis) pr0_1 pr1_1 pr2_1 pr3_1 pr4_1 pr5_1,  bar(1, fcolor(black) lcolor(black)) bar(2, fcolor(gs4) lcolor(gs4)) 
bar(3, fcolor(gs7) lcolor(gs7)) bar(4, fcolor(ltblue) lcolor(ltblue))  bar(5, fcolor(bluishgray) lcolor(bluishgray)) 
bar(6, fcolor(gs14) lcolor(gs14)) blabel(name, size(medium) color(black) margin(tiny)) legend(off) 
ylab(0(.05)0.55)  ytitle("Predicted Probability", size(medlarge) margin(small))  subtitle(Veto Players at 75th Percentile (3.95));


graph save poisson_high_bw.gph, replace;

graph bar (asis) pr0 pr1 pr2 pr3 pr4 pr5, bar(1, fcolor(black) lcolor(black)) bar(2, fcolor(gs4) lcolor(gs4)) 
bar(3, fcolor(gs7) lcolor(gs7)) bar(4, fcolor(ltblue) lcolor(ltblue))  bar(5, fcolor(bluishgray) lcolor(bluishgray)) 
bar(6, fcolor(gs14) lcolor(gs14)) blabel(name, size(medium) color(black) margin(tiny)) legend(off) 
ylab(0(.05)0.55)  ytitle("Predicted Probability", size(medlarge) margin(small))  subtitle(Veto Players at 25th Percentile (1.62));

graph save poisson_low_bw.gph, replace;

graph combine poisson_low_bw.gph poisson_high_bw.gph, xcommon ycommon iscale(*.8) 
title(Total Number of Reform Reversals (1992-2004), size(medsmall) position(6));
pause;

graph save FigureA3.gph, replace;
graph export FigureA3.eps, as(eps) preview(off) replace;


save "poisson", replace;
log close;
clear;

























